#ifndef FS_H_
#define FS_H_

/*
	Copyright (C) 2011 Salil Bhagurkar

	This file is part of illusion

	illusion is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as
	published by the Free Software Foundation, either version 3 of
	the License, or (at your option) any later version.

	illusion is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with illusion. 
	If not, see <http://www.gnu.org/licenses/>.
*/

#include <kernel/vfs.h>

/*
 * Support for file system drivers
 */

#define FS_DRIVER_NAME_LEN 32

struct fs_driver {
	char name[FS_DRIVER_NAME_LEN];
	//Try to detect the file system on a node. The node may be the
	//root node of a hardware device or any other file in the VFS
	int (*detect_fs)(struct vfs_node *dev);

	//Store your control structure at the 'files_root', so that we
	//ask you to read /write files under that node.
	int (*mount_fs)(struct vfs_node *dev, struct vfs_node *files_root);

	int (*unmount_fs)(struct vfs_node *dev, struct vfs_node *files_root);

	int (*sync_node)(struct vfs_node *dev, struct vfs_node *this);
	int (*sync_page)(struct vfs_node *dev, struct vfs_node *this, struct vfs_page *page);

	struct vfs_node *(*get_child)(struct vfs_node *dev, struct vfs_node *parent);

	struct vfs_node *(*next_child)(struct vfs_node *dev, struct vfs_node *child);

	//The vfs node that represents this file system driver
	struct vfs_node *fs;

	struct fs_driver *next, *prev;
};

struct fs_association {
	struct vfs_node *dev;
	struct fs_driver *driver;
};


extern struct vfs_node *vfs_fs;

void register_fs_driver(struct fs_driver *driver);
void unregister_fs_driver(struct fs_driver *driver);
int mount_fs(struct vfs_node *dev, struct vfs_node *fs_fs);
int detect_fs(struct vfs_node *dev, struct vfs_node *fs_fs);

#endif /* FS_H_ */
